﻿using SD.Entity;
using SD.Entity.PageSearch;
using SD.Entity.SearchEntity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SD.DataAccess.Repository
{
    public class UserInfoRepository : BaseRepository
    {
        //根据编号/主键得到一个实体
        public UserInfo GetUserInfo(int id)
        {
            string sql = @"SELECT * 
                      FROM [UserInfo]
                      WHERE Id=@Id";
            return base.Get<UserInfo>(sql, new { Id = id });
        }

        //删除一条数据
        public int DeleteUserInfo(int id)
        {
            string sql = "delete from UserInfo where Id=@Id";
            return base.Excute(sql, new { Id = id });
        }

        //获取List数据集合
        public List<UserInfo> GetUserInfoList(UserInfoSearch search)
        {
            string sql = @"SELECT *
                      FROM [UserInfo] ";
            sql += GetstrWhere(search);
            return base.Query<UserInfo>(sql, null);
        }

        //获取PagedList数据
        public PagedList<UserInfo> QueryUserInfoList(UserInfoSearch search, PageView view)
        {
            string cols = @" *";
            string strWhere = GetstrWhere(search);
            return base.PageGet<UserInfo>(view, cols, "[UserInfo]", strWhere, "Id", null);
        }


        public string GetstrWhere(UserInfoSearch search)
        {
            string strWhere = "";
            if (!String.IsNullOrEmpty(search.RoleName))
            {
                strWhere += " and RoleName=" + search.RoleName;
            }
            return strWhere;
        }
    }
}
